home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / portable / initscr.c < prev    next >
C/C++ Source or Header  |  1993-10-30  |  5KB  |  216 lines

  1. #ifndef NO_MEMORY_H
  2. #include <memory.h>
  3. #endif
  4.  
  5. #define    CURSES_LIBRARY    1
  6. #define    LOCAL_VAR
  7. #include <curses.h>
  8. #undef    initscr
  9.  
  10. #ifdef UNIX
  11. #define NOTLIB
  12. #include <defs.h>
  13. #include <term.h>
  14. /* following is to stop compilation problems with #define of lines */
  15. #undef lines
  16. #endif
  17.  
  18.  
  19.  
  20.  
  21. #ifdef PDCDEBUG
  22. char *rcsid_initscr = "$Header: C:\CURSES\portable\RCS\initscr.c 2.1 1993/06/18 20:19:03 MH Rel MH $";
  23. #else
  24. char*    _curses_notice = "PDCurses 2.0 - Public Domain 1992";
  25. #endif
  26.  
  27.  
  28.  
  29. SCREEN _cursvar = {0};        /* curses variables        */
  30.  
  31. WINDOW*    curscr;            /* the current screen image    */
  32. WINDOW*    stdscr;            /* the default screen window    */
  33. int    _default_lines = 25;    /* default terminal height    */
  34. int    LINES;            /* current terminal height    */
  35. int    COLS;            /* current terminal width    */
  36.  
  37. #if defined    DOS
  38. Regs regs;
  39. #endif
  40.  
  41. /*
  42.  * Global definitions for charget routines
  43.  */
  44. int    c_pindex = 0;        /* putter index */
  45. int    c_gindex = 1;        /* getter index */
  46. int    c_ungind = 0;        /* wungetch() push index */
  47. chtype    c_ungch[NUNGETCH];    /* array of ungotten chars */
  48. WINDOW*    _getch_win_;
  49.  
  50. /*
  51.  * Global definitions for setmode routines
  52.  */
  53. struct cttyset c_sh_tty = {0};    /* tty modes for def_shell_mode */
  54. struct cttyset c_pr_tty = {0};    /* tty modes for def_prog_mode  */
  55. struct cttyset c_save_tty = {0};
  56. struct cttyset c_save_trm = {0};
  57.  
  58. /*
  59.  * Global definitions for printscan routines
  60.  */
  61. char c_printscanbuf[513];    /* buffer used during I/O */
  62.  
  63. /*
  64.  * Global definitions for strget routines
  65.  */
  66. char *c_strbeg;
  67.  
  68. #if    EMALLOC
  69. void*    emalloc( size_t );
  70. void*    ecalloc( size_t, size_t );
  71. void    efree( void* );
  72.     
  73. extern    void*    emalloc();    /* user's emalloc(size)        */
  74. extern    void*    ecalloc();    /* user's ecalloc(num,size)    */
  75. extern    void    efree();    /* user's efree(ptr)        */
  76. #endif
  77.  
  78. #ifndef UNIX
  79. extern    void*    malloc();    /* runtime's malloc(size)    */
  80. extern    void*    calloc();    /* runtime's calloc(num,size)    */
  81. extern    void    free();        /* runtime's free(ptr)        */
  82. #endif
  83.  
  84. void*    (*mallc)();        /* ptr to some malloc(size)    */
  85. void*    (*callc)();        /* ptr to some ecalloc(num,size)*/
  86. void    (*fre)();        /* ptr to some free(ptr)    */
  87.  
  88. #ifdef CHTYPE_LONG
  89. chtype *acs_map;
  90. #endif
  91.  
  92.  
  93. /*man-start*********************************************************************
  94.  
  95.   initscr()    - Initialize terminal environment
  96.  
  97.   X/Open Description:
  98.      The first routine called should be initscr().  This will
  99.      deterine the terminal type and initialize all curses data
  100.      structures.  The initscr() function also arranges that the
  101.      first call to refresh() will clear the screen.  If errors
  102.      occur, initscr() will write an appropriate error message to
  103.      standard error and exit.  If the program wants an indication
  104.      of error conditions, newterm() should be used instead of
  105.      initscr().
  106.  
  107.   PDCurses Description:
  108.      Due to the fact that newterm() does not yet exist in PDCurses,
  109.      there is no way to recover from an error in initscr().
  110.  
  111.   X/Open Return Value:
  112.      The initscr() function returns stdscr on success and calls
  113.      exit() on error.
  114.  
  115.   X/Open Errors:
  116.      No errors are defined for this function.
  117.  
  118.   Portability:
  119.      PDCurses    WINDOW* initscr( void );
  120.      X/Open Dec '88    WINDOW* initscr( void );
  121.      BSD Curses    WINDOW* initscr( void );
  122.      SYS V Curses    WINDOW* initscr( void );
  123.  
  124. **man-end**********************************************************************/
  125.  
  126. WINDOW*    initscr(void)
  127. {
  128. #ifdef CHTYPE_LONG
  129. register int i;
  130. #endif
  131.     if  (_cursvar.alive)
  132.         return( NULL);
  133. #ifdef PDCDEBUG
  134.     if (trace_on) PDC_debug("initscr() - called\n");
  135. #endif
  136.  
  137.     if  (_cursvar.emalloc == EMALLOC_MAGIC)
  138.     {
  139. #if    EMALLOC
  140.         memset(&_cursvar, 0, sizeof(SCREEN));
  141.         _cursvar.emalloc = TRUE;
  142.         mallc = emalloc;
  143.         callc = ecalloc;
  144.         fre   = efree;
  145. #endif
  146.     }
  147.     else
  148.     {
  149.         memset(&_cursvar, 0, sizeof(SCREEN));
  150.         mallc = malloc;
  151.         callc = calloc;
  152.         fre   = free;
  153.     }
  154.  
  155. #ifdef UNIX
  156.     setupterm((char *)0,1,(int *)0);
  157.     if (enter_ca_mode != NULL)
  158.         putp(enter_ca_mode);
  159. #endif
  160.  
  161.     PDC_scr_open(&_cursvar, 0);
  162.     _cursvar.orig_cursor = _cursvar.cursor;
  163. /*    _cursvar.orig_font = PDC_get_font();*/
  164.     _cursvar.orig_font = _cursvar.font;
  165.     _cursvar.orgcbr = PDC_get_ctrl_break();
  166.     _cursvar.blank = ' ';
  167. #ifdef    FLEXOS
  168.     _flexos_16bitmode();
  169. #endif
  170. /*    savetty();*/
  171. /*    LINES = PDC_get_rows();*/
  172. /*    COLS = PDC_get_columns(); */
  173.     LINES = _cursvar.lines;
  174.     COLS = _cursvar.cols;
  175.     if (LINES < 2 || COLS < 2)
  176.     {
  177.         fprintf( stderr, "initscr(): LINES=%d COLS=%d: too small.\n",LINES,COLS );
  178.         exit( 4 );
  179.     }
  180.  
  181.     if ((curscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *) NULL)
  182.     {
  183.         fprintf( stderr, "initscr(): Unable to create curscr.\n" );
  184.         exit( 2 );
  185.     }
  186.     if ((stdscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *) NULL)
  187.     {
  188.         fprintf( stderr, "initscr(): Unable to create stdscr.\n" );
  189.         exit( 1 );
  190.     }
  191.     curscr->_clear = FALSE;
  192. #ifdef    REGISTERWINDOWS
  193.     _cursvar.refreshall = FALSE;
  194.     _inswin(stdscr, (WINDOW *)NULL);
  195. #endif
  196.  
  197. #ifdef CHTYPE_LONG
  198.     if ((acs_map = (chtype *)(*mallc)(128*sizeof(chtype))) == (chtype *)NULL)
  199.     {
  200.         fprintf( stderr, "initscr(): Unable to create acs_map.\n" );
  201.         exit( 5 );
  202.     }
  203.     for (i=0;i<128;i++)
  204.         acs_map[i] = i | A_ALTCHARSET;
  205. #endif
  206.  
  207.     _cursvar.alive = TRUE;
  208.  
  209. #ifdef UNIX
  210.     PDC_setup_keys();
  211. #else
  212.     def_shell_mode(); /* don't do this for UNIX as scropen has already done changed things */
  213. #endif
  214.     return( stdscr );
  215. }
  216.